package com.yq.ylmall.product.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yq.ylmall.model.product.ProductSku;
import com.yq.ylmall.product.service.IProductSkuService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商品 前台前端控制器
 * </p>
 *
 * @author yzk789
 * @since 2024-06-04
 */
@RestController
@Api(tags = "商品管理接口")
@RequiredArgsConstructor
@RequestMapping("/api/product")
public class ProductController {

    private final IProductSkuService productSkuService;

    @GetMapping("/test")
    public void loopUpdateProductSku() {
        List<ProductSku> skuList = productSkuService.list();
        int index = 1;
        String temp = null;
        for (ProductSku item : skuList) {
            if (!item.getProductId().toString().equals(temp)) {
                index = 1;
            }
            temp = item.getProductId().toString();
            productSkuService.update(
                    Wrappers.<ProductSku>lambdaUpdate()
                            .set(ProductSku::getSkuCode, item.getProductId() + "_" + (index++))
                            .eq(ProductSku::getId, item.getId())
            );
        }

    }

}
